package com.hencoder.hencoderpracticedraw1.practice;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.Path;
import android.graphics.RectF;
import android.os.Build;
import android.support.annotation.Nullable;
import android.util.AttributeSet;
import android.view.View;

public class Practice9DrawPathView extends View {

    public Practice9DrawPathView(Context context) {
        super(context);
    }

    public Practice9DrawPathView(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
    }

    public Practice9DrawPathView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }
    Paint paint =new Paint(Paint.ANTI_ALIAS_FLAG);
    Path path = new Path(); // 初始化 Path 对象

    {

//        RectF rect=new RectF(100,100,400,300);
//  RectF rectF=new RectF(200,200,-225,225);
        // 使用 path 对图形进行描述（这段描述代码不必看懂）
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            path.addArc(200, 200, 400, 400, -225, 225);
        }else {
//            RectF rectF=new RectF(400,200,600,400);
            RectF rectF = new RectF(200, 200, 400, 400);

            path.addArc(rectF,-225,225);
        }
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            path.arcTo(400, 200, 600, 400, -180, 225, false);
        }
        else {
            RectF rectF=new RectF(400,200,600,400);
            path.arcTo(rectF,-180,225,false);
        }
        path.lineTo(400, 542);
    }
    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);


        canvas.drawPath(path,paint);
//        练习内容：使用 canvas.drawPath() 方法画心形


    }
}
